package com.example.mytayunapi.Controller;

import com.example.mytayunapi.Entity.ordersInfo;
import com.example.mytayunapi.Service.ordersService;
import com.example.mytayunapi.Vo.ordersuserproducts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("orders")
public class ordersController {
    @Autowired
    private ordersService ordersservice;

    //点击购买插入订单信息
    //http://localhost:8080/orders/insert
    @PostMapping("/insert")
    public ResponseEntity<ordersInfo> insertOrderAndGetFullInfo(@RequestBody ordersInfo ordersInfo) {
        ordersInfo newOrderInfo = ordersservice.insertOrderAndGetFullInfo(ordersInfo);
        return ResponseEntity.ok(newOrderInfo);
    }

    //结算页面显示
    //http://localhost:8080/orders/query
    @GetMapping("/query")
    public List<ordersuserproducts> query(String School_degree) {
        return ordersservice.queryOrders(School_degree);
    }

    @GetMapping("/querid")
    public ordersInfo querid(Integer order_id) {
        ordersInfo orders = ordersservice.SelectedByOrder_id(order_id);
        return orders;

    }

    //更新订单状态
    //http://localhost:8080/orders/update
    @PostMapping("/update")
    public Integer update(ordersInfo orders) {
        return ordersservice.updateById(orders);
    }

    //更新订单状态
    //http://localhost:8080/orders/queryProid
    @GetMapping("/queryProid")
    public List<ordersInfo> queryProid(Integer Product_id) {
        return ordersservice.Selected_order_id(Product_id);
    }

    //http://localhost:8080/orders/queryorders
    @GetMapping("/queryorders")
    public List<ordersuserproducts> queryorders(String School_degree){
        return ordersservice.SelectedByOrder_Status(School_degree);
    }

    //http://localhost:8080/orders/get
    @GetMapping("/get")
    public List<ordersuserproducts> get(Integer order_id){
        return ordersservice.getUser(order_id);
    }

    //http://localhost:8080/orders/queryorderrefundid
    @GetMapping("/queryorderrefundid")
    public List<ordersuserproducts> queryOrdersRefundsByOrderId(Integer order_id){
        return ordersservice.queryOrdersRefundsByOrderId(order_id);
    }


    //http://localhost:8080/orders/queryorderid
    @GetMapping("/queryorderid")
    public List<ordersuserproducts> queryOrdersByOrderId(Integer order_id){
        return ordersservice.queryOrdersByOrderId(order_id);
    }



}
